package com.scau.controller;

import com.scau.common.message.ResponseMessage;
import com.scau.common.util.MessageUtil;
import com.scau.entity.Contract;
import com.scau.entity.Counselor;
import com.scau.entity.FollowRecord;
import com.scau.service.ContractService;
import com.scau.service.FollowRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 跟进记录
 */
@RestController
@RequestMapping("followRecords")
public class FollowRecordController {


    @Autowired
    private FollowRecordService followRecordService;

    @RequestMapping(method = RequestMethod.POST)
    public ResponseMessage<FollowRecord> create(@RequestBody FollowRecord followRecord) {


        followRecordService.add(followRecord);

        return MessageUtil.getSuccessMessage(followRecord);
    }

    /**
     * 按Id查询
     *
     * @param followRecordId
     * @return
     */
    @RequestMapping(value = "/{followRecordId}", method = RequestMethod.GET)
    public ResponseMessage<Counselor> get(@PathVariable Long followRecordId) {

        FollowRecord followRecord = followRecordService.findOne(followRecordId);

        return MessageUtil.getSuccessMessage(followRecord);
    }

    /**
     * 按条件查询
     *
     * @param followRecord
     * @param pageable
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseMessage<Page<FollowRecord>> list(FollowRecord followRecord, Pageable pageable) {

        Page<FollowRecord> followRecords = followRecordService.findAll(followRecord, pageable);

        return MessageUtil.getSuccessMessage(followRecords);
    }
}
